<?php
if(!isset($_SESSION)){session_start();};
require_once("core.php");
$PHP_SELF = "index.php";
GETMODULE($_GET[m],$_GET[p]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo WEB_TITLE; ?></title>
	<link rel='stylesheet' type='text/css' href='css/vtip.css' />
    <link rel='stylesheet' type='text/css' href='css/codeponpon-theme/jquery-ui-1.8.10.custom.css' />
<?php if($_GET['m'] == 'products' && $_GET['p'] == 'bill' || $_GET['p'] == 'print'){?>
    <link rel='stylesheet' type='text/css' href='css/bill-style.css' />
	<link rel='stylesheet' type='text/css' href='css/print.css' media="print" />
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css">

	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js"></script>
	<script type="text/javascript" src="js/jquery.ui.autocomplete.autoSelect.js"></script>
<?php }else{?>	
    <link type="text/css" href="css/styles.css" rel="stylesheet" />
    <link type="text/css" href="css/codeponpon-theme/jquery-ui-1.8.10.custom.css" rel="stylesheet" />
    <link type="text/css" href="css/jquery.fancybox-1.3.4.css" media="screen" rel="stylesheet"/>
    <link type="text/css" href="css/table_jui.css" media="screen" rel="stylesheet"/>
    <?php if($_GET['m'] == "stickers" || $_GET['pedit'] == true){?>
    	<link rel="stylesheet" href="css/jwysiwyg/jquery.wysiwyg.css" type="text/css" />
		<link rel="stylesheet" href="css/jwysiwyg/jquery.wysiwyg.modal.css" type="text/css" />
		<link rel="stylesheet" href="css/jwysiwyg/jquery.simplemodal.css" type="text/css" />
	<?php } ?>
    <?php
      if($_GET['p'] == "add_member" || $_GET['p'] == "add_customer" || $_GET['p'] == "add_saler" || $_GET['p'] == "profile"){
    ?>
    <link type="text/css" href="css/cmxform.css" media="screen" rel="stylesheet"/>
    <?php } ?>
    <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.11.custom.min.js"></script>
    <script type="text/javascript" src="js/jquery.mousewheel-3.0.4.pack.js"></script>
    <script type="text/javascript" src="js/jquery.fancybox-1.3.4.pack.js"></script>
    <script type="text/javascript" src="js/jquery.dataTables.js"></script>
    <script type="text/javascript" src="js/TableTools.js"></script>
    <script type="text/javascript" src="js/ZeroClipboard.js"></script>
    <?php
      if($_GET['p'] == "add_member" || $_GET['p'] == "add_customer" || $_GET['p'] == "add_saler" || $_GET['p'] == "profile"){
    ?>
    <script type="text/javascript" src="js/jquery.validate.js"></script>
    <?php }?>
    <script type="text/javascript" src="js/jquery.jeditable.js"></script>
    <script type="text/javascript" src="js/jquery.ajaxupload.3.5.js"></script>
    <script type="text/javascript" src="js/scripts.js"></script>
<?php }?>
	<script type="text/javascript" src="js/vtip.js"></script>
<?php
	if($_GET['m'] == "stickers" || $_GET['pedit'] == true){
?>
    <script type="text/javascript" src="js/jwysiwyg/jquery.wysiwyg.js"></script>
	<script type="text/javascript" src="js/jwysiwyg/jquery.simplemodal.js"></script>
<?php
	}
?>
<?php
	if($_GET['p'] == 'stock'){
		echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>';
		echo '<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js"></script>';
		echo '<script type="text/javascript" src="js/jquery.ui.autocomplete.autoSelect.js"></script>';
	}
?>
<script type="text/javascript">
function roundNumber(number,decimals) {
  var newString;// The new rounded number
  decimals = Number(decimals);
  if (decimals < 1) {
    newString = (Math.round(number)).toString();
  } else {
    var numString = number.toString();
    if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
      numString += ".";// give it one at the end
    }
    var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
    var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
    var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
    if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
      if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
        while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
          if (d1 != ".") {
            cutoff -= 1;
            d1 = Number(numString.substring(cutoff,cutoff+1));
          } else {
            cutoff -= 1;
          }
        }
      }
      d1 += 1;
    } 
    if (d1 == 10) {
      numString = numString.substring(0, numString.lastIndexOf("."));
      var roundedNum = Number(numString) + 1;
      newString = roundedNum.toString() + '.';
    } else {
      newString = numString.substring(0,cutoff) + d1.toString();
    }
  }
  if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
    newString += ".";
  }
  var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
  for(var i=0;i<decimals-decs;i++) newString += "0";
  //var newNumber = Number(newString);// make it a number if you like
  return newString; // Output the result to the form field (change for your purposes)
}
function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
</script>
</head>

<body>
<?php if($_GET['m'] == 'products' && $_GET['p'] == 'bill' || $_GET['p'] == 'print'){?>
<div id="page-wrap">
<?php include ($MODPATHFILE); ?>
</div>
<?php }else{ ?>
	<div class="wrapper">
    	<?php if(isset($_SESSION['login'])){ ?>        	
    	<div class="logout">
        	<a href="?m=index&p=logout" style="float:right;">
        		<img src="css/images/delete_48.png" align="ออกจากระบบ" title="ออกจากระบบ" />
            </a>
       	</div>
        <?php if($_SESSION['user'] == "superadmin"){?>
                <div class="logout">
                    <a href="?m=products&p=stock_reports" style="float:right;">
                        <img src="css/images/diagram_48.png" align="ดูรายงานสต๊อกสินค้า" title="ดูรายงานสต๊อกสินค้า" />
                    </a>
                </div>
          	<?php }?>
        <?php include ($MODPATHFILE);?>
        <!--<a href="?m=stickers&p=view" style="position:fixed;right:10px;"><img src="css/images/photo.png" width="110" /></a>-->
        <?php }elseif(isset($_GET['m']) && $_GET['m'] != 'index'){
			echo '<meta http-equiv="refresh" content="0;url=?m=index&p=index">';
		}else{
			include ($MODPATHFILE);
		} ?>
        
    </div>
<?php } ?>
</body>
</html>

